package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.ICartDeleteService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dto.DeleteCartItemRequest;
import com.mall.shopping.dto.DeleteCartItemResponse;
import com.mall.shopping.dto.DeleteCheckedItemRequest;
import com.mall.shopping.dto.DeleteCheckedItemResposne;
import com.mall.user.annotation.Anoymous;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @Description: 购物车删除
 * @Author: WD created on 2021-09-29 14:12
 * @Version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/shopping")
public class CartsDeleteController {

    @Reference(timeout = 30000, retries = 2, check = false)
    ICartDeleteService cartDeleteService;


    @DeleteMapping("/carts/{uid}/{pid}")
    public ResponseData deleteCarts(@PathVariable("uid") Long uid, @PathVariable("pid") Long pid) {
        DeleteCartItemRequest request = new DeleteCartItemRequest();

        request.setUserId(uid);
        request.setItemId(pid);
        DeleteCartItemResponse response = cartDeleteService.deleteCartItem(request);

        if (response.getCode().equals(ShoppingRetCode.SUCCESS.getCode())) {
            return new ResponseUtil().setData("成功");
        }
        return new ResponseUtil().setErrorMsg(response.getMsg());
    }


    @DeleteMapping("items/{uid}")
    public ResponseData deleteCarteSelected(@PathVariable("uid") Long uid){
        DeleteCheckedItemRequest request = new DeleteCheckedItemRequest();

        request.setUserId(uid);

        DeleteCheckedItemResposne response = cartDeleteService.deleteCheckedItem(request);
        if (response.getCode().equals(ShoppingRetCode.SUCCESS.getCode())) {
            return new ResponseUtil().setData("成功");
        }
        return new ResponseUtil().setErrorMsg(response.getMsg());

    }


}
